package com.bj.disc.ui.login.utils

import android.text.TextUtils
import com.ai3d.rfid.common.log.Logcat
import com.blankj.utilcode.util.RegexUtils

/**
 * @ProjectName : Trias
 * @Author : weijinsong
 * @Time : 2023/6/10 10:04
 * @Description : 文件描述
 */
object RegexUtils {
    private const val TAG = "RegexUtils"
    var passwordRegex = Regex("^(?=.*[a-zA-Z])(?=.*\\d).+$")

    //        var passwordRegex =
//        Regex("^(?![A-Za-z]+\$)(?![A-Z\\d]+\$)(?![a-z\\d]+\$)(?![A-Z\\W]+\$)(?![a-z\\W]+\$)(?![\\d\\W]+\$)[!-~]{8,20}\$")
    var phoneRegex = Regex("^\\+?[1-9][0-9]{7,14}$")


    fun isEmail(email: String?): Boolean {
        try {
            return RegexUtils.isEmail(email)
        } catch (e: Exception) {
            e.printStackTrace()
            return false
        }
    }

    fun isPhone(phone: String?): Boolean {
        try {
            if (TextUtils.isEmpty(phone)) {
                return false
            }
            return phoneRegex.matches(phone!!)
        } catch (e: Exception) {
            e.printStackTrace()
            return false
        }
    }

    fun isPwdRegex(pwd: String?): Boolean {
        try {
            if (TextUtils.isEmpty(pwd)) {
                return false
            }
            Logcat.d(
                TAG,
                "isPwdRegex pwd : $pwd  regex.matches(pwd!!) ${passwordRegex.matches(pwd!!) && pwd.length in 8..12}"
            )
            return passwordRegex.matches(pwd!!) && pwd.length in 8..20
        } catch (e: Exception) {
            return false
        }
    }

    private fun normalStr(s: String): Boolean {
        val len = s.length
        for (i in 0 until len) {
            val ch = s[i]
            if (!Character.isLetterOrDigit(ch)) {
                return false
            }
        }
        return len in 8..12
    }

}